﻿using System;

using SharedGenomics.Core;

namespace SharedGenomics.Annotations
{
    /// <summary>
    /// Represents the value for a given <see cref="AnnotationKey"/>
    /// </summary>
    public class AnnotationValue
    {
        private readonly AnnotationKey _key;
        private readonly object _value;

        public AnnotationValue(AnnotationKey key, object value)
        {
            key.ThrowIfNull("key");
            value.ThrowIfNull("value");

            this._key = key;
            this._value = value;
        }

        public T GetValue<T>()
        {
            return (T)this._value;
        }

        public AnnotationKey Key
        {
            get { return this._key; }
        }

        public object Value
        {
            get { return this._value; }
        }

        public override bool Equals(object obj)
        {
            var comp = obj as AnnotationValue;
            return comp != null && this.Value.Equals(comp.Value) && this.Key.Equals(comp.Key);
        }

        public override int GetHashCode()
        {
            return 17 * this.Key.GetHashCode() * this.Value.GetHashCode();
        }
    }
}
